Repository navigation
fix(functions): keep the query string and urlencoded bodies flat, as deployed functions do - #326
Conversation
…deployed functions do
Deployed AWS functions parse the query string and an
application/x-www-form-urlencoded body with Node's querystring, so a[b]=1
stays the key 'a[b]' and a repeated key becomes an array. Serve used
Express's extended qs parser for both, which built nested objects. It now
uses Express's 'simple' query parser and urlencoded({ extended: false }),
both of which are querystring.
The form-body test that sent tags[]=a now sends tags=a, the repeated-key
form AWS parses into an array; the bracket case has its own test. AGENTS.md
records the difference from Azure and GCP (V1), and the .talismanrc
checksums of the two touched files are refreshed.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
✅ BUILD PASSED - All security checks passed |
The base branch was changed.
Brings in the deps fix (#325) as merged, so this branch is up to date with v2-dev. No file changes beyond gap 6.
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
✅ BUILD PASSED - All security checks passed |
What was wrong
Deployed AWS functions (
lambda-node-bridge/cf-sv-with-helpers.ts) parse the query string (getQueryParser) and anapplication/x-www-form-urlencodedbody (getBodyParser) with Node'squerystring. That keeps keys flat:?a[b]=1&list=1&list=2gives{ 'a[b]': '1', list: ['1', '2'] }.launch:functions:serveused Express's extendedqsparser for both, which reads brackets as structure:{ a: { b: '1' } }. A function written against one shape broke on the other. HTML forms that postuser[name]=…hit this directly.This is CL-8970 gap 6.
The change (
src/functions/cloud-functions.ts)app.set('query parser', 'simple'): Express'ssimplequery parser isquerystring.parse.express.urlencoded({ extended: false, limit }): body-parser's simple parser is alsoquerystring.req.queryafter parsing (gap 5), so{ ...query, ...params }matches AWS end to end.AGENTS.md. The approved V1 differences now say the query and urlencoded bodies are flat as on AWS, and that Azure and GCP (V1) nest them..talismanrc. Refreshed checksums forcloud-functions.test.tsandAGENTS.md(test code and prose, no credentials).Tests
src/functions/cloud-functions.test.ts:keeps the query string flat, as deployed functions do:/query?a[b]=1&list=1&list=2gives{ 'a[b]': '1', list: ['1', '2'] }. It failed before the change (anested).keeps an urlencoded form flat, as deployed functions do:a[b]=1&c=2&list=1&list=2gives{ 'a[b]': '1', c: '2', list: ['1', '2'] }. It failed before the change.hands a application/x-www-form-urlencoded body to the handler as a parsed objecttest senttags[]=a&tags[]=band expectedtags. That pinned the nested behaviour this gap removes; on AWS the key istags[]. It now sendstags=a&tags=b, the repeated-key form AWS turns into an array, and keeps its expected object. The bracket case has its own test above.Full suite in the pre-push hook: 189 suites, 3829 tests passed (also after merging v2-dev, at b11d948). Every hook ran, with no
--no-verify.E2E (http-sanity cloud-functions checks, AWS expectations)
Against
launch:functions:serve, with the 25 checks from e2e PR contentstack/contentfly-e2e-tests#500:the query string stays flat;an urlencoded form stays flat;a query key ending in [] stays a key;an urlencoded form keeps [] in the key and a repeated key as an array.req.bodywith no body; raw request stream) and 10 (require,__dirname).#500 adds the
[]cases (tags[]=a), whichqsreads astags. Azure and GCP (V1) are recorded as known gaps, and everything runs behindLAUNCH_E2E_CLOUD_FUNCTION_PARITY.Not changed
querystring.parsekeeps the first 1000 keys. body-parser answers 413 "too many parameters" instead, as it already did withqs.charseton a form is refused with 415 by body-parser. AWS ignores the charset. This is unchanged from before.Jira: https://contentstack.atlassian.net/browse/CL-8970
Generated by Claude Code